{
open Parser
open Fonctionparsing

let ligne = ref 1;;
let col = ref 1;;
let mot = ref "";;

exception Error of int * string

let error pos msg = 
	raise (Error (pos,msg))

}

rule token = parse
| ":="           				   						   {begin col := (!col+2) ; AFFECTATION end}
| '+'           				   						   {begin col := (!col+1) ; PLUS end}
| '-'            				  						   {begin col := (!col+1) ; MOINS end}
| '/'            				   						   {begin col := (!col+1) ; DIV end}
| '*'            				   						   {begin col := (!col+1) ; MUL end}
| '>'								   					   {begin col := (!col+1) ; SUP end}
| '<'								   					   {begin col := (!col+1) ; INF end}
| ">="							   						   {begin col := (!col+2) ; SUPEGAL end}
| "<="							   						   {begin col := (!col+2) ; INFEGAL end}		
| '='								   					   {begin col := (!col+1) ; EGAL end}
| "<>"							   						   {begin col := (!col+2) ; DIFF end}
| "true"						   						   {begin col := (!col+4) ; TRUE end}
| "false"						   						   {begin col := (!col+5) ; FALSE end}
| "!"							   						   {begin col := (!col+1) ; NOT end}
| "&&"							   						   {begin col := (!col+2) ; ET end}
| "||"							   						   {begin col := (!col+2) ; OU end}
| "integer"							   					   {begin col := (!col+7) ; INT end}
| "return"						   						   {begin col := (!col+6) ; RT end}
| "function"					   						   {begin col := (!col+8) ; MOTFONCTION ("function") end}
| "procedure"					   						   {begin col := (!col+9) ; MOTPROCEDURE ("procedure") end}
| "if"							   						   {begin col := (!col+2) ; IF end}
| "then"						   						   {begin col := (!col+4) ; THEN end}
| "else"						   						   {begin col := (!col+4) ; ELSE end}
| "while"						   						   {begin col := (!col+5) ; WHILE end}
| "begin"						   						   {begin col := (!col+5) ;  BG end }
| "do"							   						   {begin col := (!col+2) ; DO end}
| "end"							   						   {begin col := (!col+3) ; END end}
| "is"							   						   {begin col := (!col+2) ; IS end}
| "("							   						   {begin col := (!col+1); PARENTHESEOUVRANTE end}
| ")"							   						   {begin col := (!col+1); PARENTHESEFERMANTE end}
| "["							   						   {begin col := (!col+1); CROCHETOUVRANT end}
| "]"						       						   {begin col := (!col+1); CROCHETFERMANT end}
| ","							   						   {begin col := (!col+1); VIRGULE end}
| ";"							   						   {begin col := (!col+1); POINTVIRGULE end}
| ":"							   						   {begin col := (!col+1); DEUXPOINTS end}
| '\n'													   {begin incr ligne; col := 0 ; token lexbuf end}
| ' '													   {begin col := (!col+0) ; token lexbuf end}
| "//" [^'\n']* '\n'?  									   {token lexbuf}
| "/*"  {incomment lexbuf}
(* Règles supplémentaires *)
| [' ''\n''\t' ] {token lexbuf} (*  permet d'enlever les blancs *)
| "" { EOF }
| ['0'-'9']+     										   {
																let nombre_s = (Lexing.lexeme lexbuf) in 
																begin
																	col := (!col+1);
																	mot := nombre_s;
																	N (int_of_string nombre_s) 
																end
															}
| ['a'-'z' 'A'-'Z']+['a'-'z' 'A'-'Z' '0'- '9']* as ident   {begin mot := ident; col:= (!col+String.length(ident)); (X(ident)) end}

and incomment = parse
| "*/"  {token lexbuf}
| _     {incomment lexbuf}
| eof {error (Lexing.lexeme_start lexbuf) "commentaire non terminé"}
